﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TMS
{
    public partial class StocktakingListsControl : UserControl
    {
        Stocktaking stocktaking = new Stocktaking();

        public StocktakingListsControl()
        {
            InitializeComponent();
        }

        public StocktakingListsControl(DataGridViewRow parameters)
        {
            InitializeComponent();
            Program.GetMainForm.Text = "TMS - Пописни листи од попис:" + parameters.Cells[1].Value.ToString();
            stocktaking.ID =Convert.ToInt32(parameters.Cells[0].Value);
            stocktaking.Date = Convert.ToDateTime(parameters.Cells[1].Value);
            dgvStocktakingList.DataSource = stocktaking.GetAllStocktakingLists().Tables[0];
            dgvStocktakingList.Columns[0].Visible = false;
            dgvStocktakingList.Columns[1].Visible = false;
            dgvStocktakingList.Columns[2].HeaderText = "Датум на попис";
            dgvStocktakingList.Columns[3].HeaderText = "Опис";
            dgvStocktakingList.Columns[4].HeaderText = "Одговорен";
            if (parameters.Cells[2].Value.ToString() == "затворен")
            {
                ToStEdit.Visible = false;
                ToStNew.Visible = false;
            }
        }

        private void dgvStocktakingList_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            Program.GetMainForm.registerInHistoryMain(ControlsEnum.STOCKTAKING_PRODUCTS_CONTROL, dgvStocktakingList.CurrentRow);
            Program.GetMainForm.ShowControl(ControlsEnum.STOCKTAKING_PRODUCTS_CONTROL, dgvStocktakingList.CurrentRow);
            this.Dispose();
        }

        private void btnNewStocktakingList_Click(object sender, EventArgs e)
        {
            DataGridView dgvtmp = new DataGridView();
            dgvtmp.RowCount = 1;
            dgvtmp.ColumnCount = 2;
            dgvtmp.Rows[0].Cells[0].Value = stocktaking.ID;
            dgvtmp.Rows[0].Cells[1].Value = stocktaking.Date;
            Program.GetMainForm.registerInHistoryMain(ControlsEnum.CREATE_EDIT_STOCKTAKING_LISTS_CONTROL, dgvtmp.Rows[0]);
            Program.GetMainForm.ShowControl(ControlsEnum.CREATE_EDIT_STOCKTAKING_LISTS_CONTROL,dgvtmp.Rows[0]);
            this.Dispose();
        }

        private void btnEditStocktakingList_Click(object sender, EventArgs e)
        {
           
            if (dgvStocktakingList.SelectedRows.Count > 0)
            {
                Program.GetMainForm.registerInHistoryMain(ControlsEnum.CREATE_EDIT_STOCKTAKING_LISTS_CONTROL, dgvStocktakingList.SelectedRows[0]);
                Program.GetMainForm.ShowControl(ControlsEnum.CREATE_EDIT_STOCKTAKING_LISTS_CONTROL, dgvStocktakingList.SelectedRows[0]);
                this.Dispose();
            }
            else
                MessageBox.Show("Немате селектирано пописна листа");
        }


        private void ToStBack_Click(object sender, EventArgs e)
        {
            if (Program.GetMainForm.Back())
                this.Dispose();
        }


        private void ToStForward_Click(object sender, EventArgs e)
        {
            if (Program.GetMainForm.Forward())
                this.Dispose();
        }


    }
}
